from django.shortcuts import render
from django.views import View
from django.http import HttpResponse
from django.utils.decorators import method_decorator
# Create your views here.



def templates_demo(request):
    """演示模板使用"""
    context = {
        'name': '大表哥',
        'alist': [2, 5, 1],
        'adict': {'age': 20}
    }  # 要传到模板文件中进行渲染的数据必须是以字典的格式传入
    return render(request, 'index.html', context=context)


def my_decorator(func_view):

    def wrapper(request, *args, **kwargs):
        print("装饰器被调用了")
        return func_view(request, *args, **kwargs)

    return wrapper

# @my_decorator
# def test(request):
#     return HttpResponse('ok')


# @my_decorator
# @method_decorator(my_decorator, name='要装饰类视图中的那个方法')  method_decorator主要解决了装饰器中self参数问题
# @method_decorator(my_decorator, name='dispatch')
# @method_decorator(my_decorator, name='get')
class DemoView(View):
    """类视图"""
    # 类视图中定义的方法必须是请求方法名字小写

    # @my_decorator
    def get(self, request):

        return HttpResponse('get请求业务逻辑')

    @method_decorator(my_decorator)
    def post(self, request):
        return HttpResponse('post请求业务逻辑')


# def func():
#     print("xx")

# func()
# abc = func
# abc()
# hander = get
# get()
# hander()
# demoobj  = DemoView()
# func_view = demoobj.get
# func_view()